﻿using System;
using System.Text;
using System.Threading.Tasks;
using CsharpTool.SignalRServer;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;

namespace CsharpTool.Common
{
    [ApiController]
    [Route("test")]
    public class TestApiController : ControllerBase
    {
        private readonly IMessageSend _messageSend;

        /// <summary>
        /// ctor
        /// </summary>
        public TestApiController(IMessageSend messageSend)
        {
            _messageSend = messageSend;
        }

        /// <summary>
        /// 服务端发送消息
        /// </summary>
        [HttpPost("hub-server-send")]
        public async Task ServerSendAsync()
        {
            var data = new MsgInfo<string>
            {
                Type = "Hub.Msg.Server",
                Group = "Test",
                Data = $"服务端推送数据:{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss}"
            };
            await _messageSend.SendMsgAllAsync(data);
        }
    }
}
